package com.xunjing.log.controller;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xunjing.common.core.web.domain.MyBaseEntity;
import com.xunjing.log.domain.IcPayLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xunjing.common.log.annotation.Log;
import com.xunjing.common.log.enums.BusinessType;
import com.xunjing.common.security.annotation.RequiresPermissions;
import com.xunjing.log.domain.IcCheLog;
import com.xunjing.log.service.IIcCheLogService;
import com.xunjing.common.core.web.controller.BaseController;
import com.xunjing.common.core.web.domain.AjaxResult;
import com.xunjing.common.core.utils.poi.ExcelUtil;
import com.xunjing.common.core.web.page.TableDataInfo;

/**
 * 支付查询日志Controller
 *
 * @author zhangyt
 * @date 2024-03-27
 */
@RestController
@RequestMapping("/chelog")
public class IcCheLogController extends BaseController {
    @Autowired
    private IIcCheLogService icCheLogService;

    /**
     * 查询支付查询日志列表
     */
    @RequiresPermissions("chelog:chelog:list")
    @GetMapping("/list")
    public TableDataInfo list(IcCheLog icCheLog) {
        startPage();
        LambdaQueryWrapper<IcCheLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.ge(MyBaseEntity::getCreateTime,LocalDateTime.now().plusMonths(-2));
        wrapper.le(MyBaseEntity::getCreateTime,LocalDateTime.now());
        List<IcCheLog> list = icCheLogService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 导出支付查询日志列表
     */
    @RequiresPermissions("chelog:chelog:export")
    @Log(title = "支付查询日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IcCheLog icCheLog) {
        List<IcCheLog> list = icCheLogService.selectIcCheLogList(icCheLog);
        ExcelUtil<IcCheLog> util = new ExcelUtil<IcCheLog>(IcCheLog.class);
        util.exportExcel(response, list, "支付查询日志数据");
    }

    /**
     * 获取支付查询日志详细信息
     */
    @RequiresPermissions("chelog:chelog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(icCheLogService.getById(id));
    }

    /**
     * 新增支付查询日志
     */
    @RequiresPermissions("chelog:chelog:add")
    @Log(title = "支付查询日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IcCheLog icCheLog) {
        icCheLog.setFlag("N");
        icCheLog.setCreateBy("sd");
        icCheLog.setUpdateBy("sd");
        icCheLog.setRemark("sdsd");
        icCheLog.setCreateTime(LocalDateTime.now());
        return toAjax(icCheLogService.save(icCheLog));
    }

    /**
     * 修改支付查询日志
     */
    @RequiresPermissions("chelog:chelog:edit")
    @Log(title = "支付查询日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IcCheLog icCheLog) {
        return toAjax(icCheLogService.updateById(icCheLog));
    }

    /**
     * 删除支付查询日志
     */
    @RequiresPermissions("chelog:chelog:remove")
    @Log(title = "支付查询日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(icCheLogService.removeByIds(Arrays.asList(ids)));
    }
}
